home *** CD-ROM | disk | FTP | other *** search
Wrap
using System; using System.Collections; using System.ComponentModel; using System.Data.Common; using System.Data.OleDb; using System.Globalization; using System.Reflection; using System.Threading; using System.IO; using System.Xml; using System.Web; using System.Web.SessionState; using System.Web.UI.WebControls; using GBPVR.Public; using GBPVRSchedule; namespace gbweb { /// <summary> /// Summary description for Global. /// </summary> public class Global : System.Web.HttpApplication { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null; public Global() { InitializeComponent(); } static Global() { lock (typeof(Schedule)) { // TODO: Make this a setting to switch between GBPVR and CDK scheduler settings = new Settings(); Type scheduleType = Type.GetType("GBPVRSchedule." + Settings.schedule + "Schedule"); schedule = scheduleType.InvokeMember(null, BindingFlags.CreateInstance, null, null, null) as Schedule; } } private static Schedule schedule; public static Schedule Schedule { get { return schedule; } } private static Settings settings; public static Settings Settings { get { return settings; } } public static XmlDocument Config { get { if (HttpContext.Current.Session["config"] == null) { // find config.xml location string configFile = Path.Combine(Global.Settings.GetInstallDir(), "config.xml"); // special check for sub's development machine if (File.Exists(configFile) == false) { if (File.Exists(@"c:\temp\config-master.dont-edit-me.xml")) { configFile = @"c:\temp\config-master.dont-edit-me.xml"; } else { Logger.Error("Error finding config.xml"); } } // load config XmlDocument configDoc = new XmlDocument(); configDoc.Load(configFile); HttpContext.Current.Session["config"] = configDoc; } return (XmlDocument)HttpContext.Current.Session["config"]; } } public static DbConnection GetOpenGBPVRDbConnection() { DbProviderFactory dbProviderFactory = DatabaseHelperFactory.getDbProviderFactory(); DbConnection dbConnect = dbProviderFactory.CreateConnection(); dbConnect.ConnectionString = DatabaseHelperFactory.getDbConnectionString(); dbConnect.Open(); return dbConnect; } public static void FillChannelList(DropDownList listChannels) { //Instantiate a schedule Schedule scheduleHelper = Global.Schedule; //Pull in a list of shows to get a listing of available channels IList listingsForPeriod; listingsForPeriod = scheduleHelper.GetListingsForTimePeriod(DateTime.Now, DateTime.Now); //Load the channel list box with available channels foreach (Channel channel in listingsForPeriod) { listChannels.Items.Add(new ListItem(channel.getName(), channel.getOID().ToString())); } } public static void FillGenreList(Object GenreList) { // create the database connection DbConnection aConnection = GetOpenGBPVRDbConnection(); // create the command object and store the sql query DbCommand aCommand = aConnection.CreateCommand(); aCommand.CommandText = "select genre_name from genre order by genre_name"; aCommand.Connection = aConnection; // create the datareader object to connect to table DbDataReader aReader = aCommand.ExecuteReader(); if (GenreList is ListBox) { ListBox genreList = (ListBox)GenreList; // iterate through the results to load the genre list while (aReader.Read()) { genreList.Items.Add(aReader.GetString(0)); } GenreList = genreList; } else { DropDownList genreList = (DropDownList) GenreList; // load the first record to the list for no preference genreList.Items.Add("Choose Genre..."); // iterate through the results to load the genre list while (aReader.Read()) { genreList.Items.Add(aReader.GetString(0)); } GenreList = genreList; } // close the reader aReader.Close(); // NB: close the connection aConnection.Close(); } /* protected void Application_Start(Object sender, EventArgs e) { } protected void Session_Start(Object sender, EventArgs e) { } */ protected void Application_BeginRequest(Object sender, EventArgs e) { if (Request.UserLanguages != null) { Thread currentThread = Thread.CurrentThread; foreach (string language in Request.UserLanguages) { try { currentThread.CurrentCulture = new CultureInfo(language.Split(";".ToCharArray(), 2)[0]); break; } catch { } } currentThread.CurrentUICulture = currentThread.CurrentCulture; } } /* protected void Application_EndRequest(Object sender, EventArgs e) { } protected void Application_AuthenticateRequest(Object sender, EventArgs e) { } */ protected void Application_Error(Object sender, EventArgs e) { // Log file ends up being C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\gbpvr\2364619e\429af7e1\assembly\dl2\07d20234\00d91a5d_07d7c401\<appdomain>.log // Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName is not the best source for the log filename // System.Reflection.Assembly.GetEntryAssembly(); // string logdir = AppDomain.CurrentDomain.BaseDirectory.Replace("/", @"\"); Logger.Error(Server.GetLastError().ToString()); } /* protected void Session_End(Object sender, EventArgs e) { } protected void Application_End(Object sender, EventArgs e) { } */ #region Web Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.components = new System.ComponentModel.Container(); } #endregion } }